package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"video/models"
)

type VideoController struct {
	beego.Controller
}

type JsonR struct {
	Code     int         `json:"code"`
	Msg      string      `json:"msg"`
	Database interface{} `json:"database"`
}

func (c *VideoController) Add() {
	title := c.GetString("title")
	status := c.GetString("status")
	time := c.GetString("time")
	people := c.GetString("people")
	video := models.Video{
		Title:  title,
		Status: status,
		Time:   time,
		People: people,
	}
	err := models.DB.Create(&video).Error
	if err != nil {
		c.Data["json"] = JsonR{
			Code:     0,
			Msg:      "添加失败",
			Database: nil,
		}
		c.ServeJSON()
	} else {
		c.Data["json"] = JsonR{
			Code:     200,
			Msg:      "添加成功",
			Database: video,
		}
		c.ServeJSON()
	}
}
